# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=kubeone
pkgver=1.7.4
# Use the latest stable Kubernetes version at the time as the default (https://dl.k8s.io/release/stable-1.27.txt).
# See https://docs.kubermatic.com/kubeone/main/tutorials/creating-clusters/#step-5--provisioning-the-cluster for
# the table of compatible Kubernetes versions.
_k8sver=1.27.13
pkgrel=0
pkgdesc="Automate Kubernetes cluster operations on all platforms"
url="https://kubeone.io/"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/kubermatic/kubeone/archive/refs/tags/v$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X k8c.io/kubeone/pkg/cmd.commit=AlpineLinux
	-X k8c.io/kubeone/pkg/cmd.version=$pkgver
	-X k8c.io/kubeone/pkg/cmd.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X k8c.io/kubeone/pkg/cmd.defaultKubeVersion=$_k8sver
	-X k8c.io/kubeone/pkg/cmd.defaultCloudProviderName=none
	"

	go build -v -ldflags "$_goldflags"

	mkdir -p man
	./kubeone document man -o man/

	for shell in bash zsh; do
		./kubeone completion $shell > kubeone.$shell
	done
}

check() {
	go test ./pkg/... ./test/...
}

package() {
	install -Dm755 kubeone -t "$pkgdir"/usr/bin/

	install -Dm644 man/*.1 -t "$pkgdir"/usr/share/man/man1/

	install -Dm644 kubeone.bash \
		"$pkgdir"/usr/share/bash-completion/completions/kubeone
	install -Dm644 kubeone.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_kubeone
}

sha512sums="
b32b277b9fd0ea0495ac8712c378e22f38ac3a6d84b98bf38ca43ee801ac75818d214c518b41a1bc047b09bc1e8f145fc6bf435d334b15ed3fd5a20dee8493e6  kubeone-1.7.4.tar.gz
"
